package mx.com.fractal.ristorante.service.impl;

import mx.com.fractal.ristorante.dao.ReservacionDAO;
import mx.com.fractal.ristorante.dto.ReservacionDTO;
import mx.com.fractal.ristorante.service.ReservacionService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ReservacionServiceImpl implements ReservacionService {
	
	@Autowired
	private ReservacionDAO reservacionDAO;
	private static final Logger logger=Logger.getLogger(ReservacionServiceImpl.class);

	@Transactional
	public void save(ReservacionDTO reservacion) throws Exception {
		Integer id = reservacionDAO.save(reservacion);
		logger.trace("Id de reservacion guardado: " + id);
		reservacion.setIdReservacion(id);
		if(reservacion.getMesas()!= null && reservacion.getMesas().size() > 0){
			int[] result = reservacionDAO.saveReservacionMesa(id, reservacion.getMesas());
			logger.trace("Se guarda correctamente la relacion mesa - reservacion --> " + result);
		}
		
	}
	
}
